<?php

declare(strict_types=1);

namespace App\Game\Model;

use Hyperf\Database\Model\Relations\HasMany;
use Hyperf\Database\Model\Relations\HasOne;
use Mine\MineModel;

/**
 * @property int $id 主键
 * @property int $user_id 用户id
 * @property int $game_id 游戏id
 * @property int $status 1收藏
 * @property string $last_at 浏览时间
 * @property int $view 1浏览
 * @property-read null|Game $game
 */
class GameFavorite extends MineModel
{
    public bool $timestamps = false;
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'game_favorite';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'user_id', 'game_id', 'status', 'last_at', 'view'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'user_id' => 'integer', 'game_id' => 'integer', 'status' => 'integer', 'view' => 'integer'];

    public function game(): HasOne
    {
        return $this->hasOne(Game::class, 'id', 'game_id');
    }

    public function tag(): HasMany
    {
        return $this->hasMany(GameTag::class, 'game_id', 'game_id')->with(['tag:id,name,icon']);
    }
}
